<style>
	.show{display: inherit}
	.hide{display: none}
	.layui-btn{margin-right: 10px !important;}
	.layui-btn-group .layui-btn{margin-left: 10px !important;}
	.layui-table-cell {overflow-x: hidden;overflow: inherit; }
	.layui-table-cell{padding:2px 4px;line-height:20px;text-align:center;}
	th span,.layui-table-cell{white-space:normal;}
	.layui-form-item .layui-inline{margin-right:0px;}
	.createBillTemp{line-height:38px;}
	.createBillTemp select{width:180px;height:30px;}
	.fixed-bar{height:auto !important;}
	.redclass{color:red;font-weight:bold;}
	.check{margin-left:8px;}
	.unit_count{text-decoration: underline;padding: 0px 8px;cursor: pointer;color: #3399FF;}
	 body .demo-class .layui-layer-title{background:#FFFFFF;  border: none;}
	 .add_invo_red{background: #d49c81}
	 .help-diy-css{color:red}
	 /* .layui-layer-hui .layui-layer-content{text-align: left!important;color:#FFFFFF!important;font-size: 13px!important;}
	 .layui-layer-dialog{width:500px!important;background-color: #b3b3b3!important;}*/
    /*调用库存样式*/
	.dress_line_code{margin-top:6px;}
	.dress_line_code textarea{height:100px;padding:6px;width:578px}
	.submit_block{padding-left:230px;}
	.checkin_ret{text-align:center;padding-top:30px;}
	.scan_code_ret{color:red;font-weight:bold;margin-bottom:6px;}
	.defective_reason input{padding:2px 4px;}

</style>
<div class="fixed-bar" style="clear:both;">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',['status' => $status])}"  method="get" id="hisi-table-search">
		<div class="layui-form-item">
			<div class="layui-inline ordernum_input_search">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
				</div>
			</div>
			<div class="layui-inline package_num_search">
				<label class="layui-form-label ">大包编号</label>
				<div class="layui-input-inline">
					<input type="text" name="package_num" lay-verify="" placeholder="输入大包编号" class="layui-input">
				</div>
			</div>
			<div class="layui-inline sku_input_search">
				<label class="layui-form-label">sku</label>
				<div class="layui-input-inline">
					<input type="text" name="sku" lay-verify="" placeholder="输入sku" class="layui-input">
				</div>
			</div>
			<div class="layui-inline size_search_input">
				<label class="layui-form-label">尺码</label>
				<div class="layui-input-inline">
					{:Form::select('size_name', '', $sizeList, '', '')}
				</div>
			</div>
			<div class="layui-inline factory_serarch_input">
				<label class="layui-form-label">工厂</label>
				<div class="layui-input-inline">
					{:Form::select('factory_id', '', $factoryKV, '', '')}
				</div>
			</div>
<!--			<div class="layui-inline status_serarch">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline">
					{:Form::select('order_status', '', ['' => '全部', 1=>'待打包'], '', '')}
				</div>
			</div>-->
			<div class="layui-inline created_search">
				<label class="layui-form-label ">日期</label>
				<div class="layui-input-inline">
					<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择创建日期" class="layui-input">
				</div>
			</div>
			<div class="layui-inline tail_stock_search">
				<label class="layui-form-label">出入库方式</label>
				<div class="layui-input-inline">
					{:Form::select('stock_method', '', ['' => '全部', 1=>'入库', 2=>'出库'], '', '')}
				</div>
			</div>

			<div class="layui-inline order_type_search">
				<label class="layui-form-label">订单类型</label>
				<div class="layui-input-inline">
					{:Form::select('remark', '', ['' => '全部', 1=>'订单', 2=>'尾货'], '', '')}
				</div>
			</div>

			<div class="layui-inline searchSubmit">
				<button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
				<button type="button" class="layui-btn layui-btn-primary hisi-export topsearch">导出</button>
			</div>
		</div>
	</form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
	<ul class="layui-tab-title">
		<li class="layui-this"><a onclick="statCli(0)" href="#">尾货待处理（<span class="red bold stat-num-1">{:arrayGet($statData, 0, 0)}</span>条）</a></li>
		<li><a onclick="statCli(1)" href="#">打包待发货（<span class="red bold stat-num-2">{:arrayGet($statData, 1, 0)}</span>条）</a></li>
		<li><a onclick="statCli(2)" href="#">入库明细（<span class="red bold stat-num-3">{:arrayGet($statData, 2, 0)}</span>条）</a></li>
		<li><a onclick="statCli(3)" href="#">出库明细（<span class="red bold stat-num-4">{:arrayGet($statData, 3, 0)}</span>条）</a></li>
		<li><a onclick="statCli(4)" href="#">已完成（<span class="red bold stat-num-5">{:arrayGet($statData, 4, 0)}</span>条）</a></li>
	</ul>
	<div class="layui-tab-content">
		<table id="dataTable" lay-filter="demoEvent"></table>
	</div>
</div>

<div id="StockCheckOut" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			<div class="scan_code">
				<div class="dress_line_code">
					请扫描要出库的服装：(注：一行一个服装条码)<br />
					<textarea name="out_dress_line_code" id="out_dress_line_code" class="layui-area out_code_input" lay-verify="" placeholder="扫描要出库的服装条码"></textarea>
					<input type="hidden" name="sku_stock" class="sku_stock" value='{{d.sku_stock}}'>
				</div>
				<div class="scan_code_block">验证提示：<span class="scan_code_ret"></span></div>
				<div class="submit_block">
					<button class="layui-btn" lay-submit lay-filter="stock-out-out" >确认出库</button>
				</div>
			</div>
			<div class="checkin_ret hide">处理结果：<span class="act_ret_str"></span>出库成功；<br /></div>
			<div>
				&nbsp;
			</div>
			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<input type="hidden" name="size_name" class="size_name_input" value="" lay-reqText="尺码请选择">
			<input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描要出库的服装条码"  class="layui-input outcheckinNum">
			<div>&nbsp;</div>
		</div>
	</form>
</div>

<div id="stockOutInTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			{{#  for(var i in d.list){ }}
			<div class="layui-inline">
				<label class="layui-form-label">{{ d.list[i].size_name }}</label>
				<div class="layui-input-inline">
					<input type="text" name="number[{{ d.list[i].mid }}]" value="" lay-verify="number|required" placeholder="输入数量" class="layui-input">
				</div>
			</div>
			{{#  } }}

			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<div class="layui-inline fr">
				<button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认</button>
			</div>
		</div>
	</form>
</div>

{include file="system@block/layui" /}
<script type="text/html" id="OrdernumTpl_red">
	{{# if(d.is_tail_manage==-1){ }}
	<span class="copy-item add_invo_red">{{ d.client_ordernum }}</span> <br>
	{{# }else{ }}
	<span class="copy-item">{{ d.client_ordernum }}</span> <br>
	{{# } }}
</script>
<script type="text/html" id="OrdernumTpl">
	<span class="copy-item">{{ d.client_ordernum }}</span> <br>
</script>
<script type="text/html" id="packageOrder_num">
	<span class="copy-item">{{ d.packageOrder_num }}</span> <br>
</script>
<script type="text/html" id="packagenum">
	<span class="copy-item">{{ d.package_num }}</span> <br>
</script>

<script type="text/html" id="sku2Tpl">
	<span class="copy-item" style="word-wrap:break-word">{{ d.sku }}</span>
</script>

<script type="text/html" id="skuimgTpl">
	<span class="lay-pic-container" src="{{ d.ori_pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>
<script type="text/html" id="#pack_status">
	{{ d.status }}
</script>

<script type="text/html" id="factoryTpl">
	<span class="blue">{{d.quantity}}</span>
</script>
<script type="text/html" id="tail_over_time">
	{{# if(d.tail_over_time != 0){ }}
	     {{d.tail_over_time}}
	{{# }else{ }}
	      无
	{{# } }}

</script>

<script type="text/html" id="materialTpl">
	{{# if(d.is_share== 1){ }}
	<a class="layui-btn layui-btn-normal layui-btn-xs layui-bg-orange">共</a>
	{{# } }}
	<span class="copy-item">{{ d.mInfo.name }}</span><br />
	{{d.mInfo.color}}
</script>
<script type="text/html" id="total_num_new">
	{{# if(d.status== 3 ){ }}
		<span class="unit_count" onclick="openCheckoutWindow('{{ d.client_ordernum}}','{{ d.status}}')">{{ d.total_num}}</span>
	{{# }else if(d.status== 1 || d.status== 2){ }}
		<span class="unit_count" onclick="openCheckoutWindow('{{ d.package_num}}','{{ d.status}}')">{{ d.total_num}}</span>
	{{# }else{ }}
		{{# if(d.package_num ==0){ }}
		<span class="unit_count" onclick="openCheckoutWindow('{{ d.client_ordernum}}','-100','client_ordernum','{{d.status_two}}')">{{ d.total_num}}</span>
		{{# }else{ }}
		<span class="unit_count" onclick="openCheckoutWindow('{{ d.package_num}}','-100','','{{d.status_two}}')">{{ d.total_num}}</span>
		{{# } }}
	{{# } }}
</script>

<script type="text/html" id="total_need_num">
	{{ d.total_need_num}}
</script>
<script type="text/html" id="total_need_num_out">
	{{ d.total_need_out_num}}
</script>
<script type="text/html" id="tail_goods_dff_end">
	{{ d.tail_goods_dff_end}}
</script>

<script type="text/html" id="unit">
	{{d.mInfo.unit}}
</script>
<script type="text/html" id="color">
	{{d.mInfo.color}}
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
	<a href="{:url('stallCost/add')}?stall_feed_id={{d.id}}" class="hisi-iframe blue" hisi-data="{width: '70%', height: '70%'}" title="费用单">增加费用单</a></br>
	<a href="{:url('stallCost/stallCostDetail')}?stall_feed_id={{d.id}}" title="费用单" class="hisi-iframe blue" hisi-data="{width: '70%', height: '90%'}">查看费用单</a>
</script>
<script type="text/html" id="toolbar">
	<div class="layui-btn-group fr_tail_manage" id="wanchengok">
		<a href="#" onclick="addInvoice()" class="layui-btn layui-btn-sm  layui-icon check">新增入库单</a>&nbsp;&nbsp;
		<a  href="#" onclick="openPackageWindow(102)"   title="生成入库大包"
			class="layui-btn layui-btn-danger layui-btn-sm layui-icon check">生成入库大包</a>&nbsp;
		<a href="#"   onclick="openPackageWindow(103)"    class=" layui-btn layui-btn-primary layui-btn-sm confirmon "  >确定出库</a>&nbsp;&nbsp;
		<a data-href="#"  onclick="openPackageWindow(104)"  class="layui-btn layui-btn-primary layui-btn-sm  layui-icon check">无需处理</a>&nbsp;&nbsp;
		<a href="#"   class= "layui-icon layui-icon-tips help-diy-css check">帮助?</a>
		<a href="#"   onclick="openPackageWindow(201)" class="layui-btn layui-btn-primary layui-btn-sm  layui-icon back">退出大包</a>&nbsp;&nbsp;
		<a href="#" onclick="openPackageWindow(202)"  class="layui-btn layui-btn-primary layui-btn-sm make-bill ">发货</a>
		<a href="#"  onclick="openPackageWindow(203)"  class="layui-btn layui-btn-primary layui-btn-sm make-bill  createBillList">打印清单</a>

		<a href="#" onclick="openPackageWindow(301)"   class="layui-btn layui-btn-primary layui-btn-sm cancelOrders">退货</a>

		<a href="#"  class="layui-btn layui-btn-primary layui-btn-sm checkOutDetailedNew" onclick="openPackageWindow(401)" >打印清单</a>
		<a href="#" onclick="openPackageWindow(402)" class="layui-btn layui-btn-primary layui-btn-sm tail-stock-out checkOutDetailedNew">调用库存</a>

	</div>
</script>
<script type="text/html" id="detailTpl">
	<a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" title="明细表" class="hisi-iframe blue" hisi-data="{width: '100%', height: '100%'}">打开</a>
	<!--    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}" method="get" id="hisi-table-search">-->
	<a href="{:url('StallBillFeed/stallBillFeedDetail')}?stall_bill_id={{d.id}}&export=1" style="cursor:pointer;border: none" class="blue hisi-export">下载</a>
	<!--    <form>-->
</script>
<script type="text/html" id="stallIdTpl">
	<div class="stall-select">
		{:Form::select('stall_id','', $stallsKV, 'stall-ids-{literal}{{d.id}}{/literal}', 'layui-input stall-ids','lay-search="" lay-filter="stallIds" lay-verify="required" data-id="{literal}{{d.id}}{/literal}"')}
	</div>
</script>
<script type="text/javascript">
	var clientStatus = {:json_encode($clientStatus);};
	var factoryKV= {:json_encode($factoryKV);};
	layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
		var $ = layui.jquery;
		var table = layui.table;
		var laydate = layui.laydate;
		var form = layui.form;
		var laytpl=layui.laytpl;
		var layer = layui.layer;
		var initialize=0,second_initialize=0,first_init=0,changetab=0;
		laydate.render({
			elem: '#create_date_range'
			,range: '~'
			,theme: 'molv'
			,mark: {'{:$today}':''}
			,change: function(value, date, endDate){
				$('#create_date_range').val(value);
				$('#layui-laydate1').remove();//关闭面板
			}
		});
		laydate.render({
			elem: '#create_date_range1'
			,range: '~'
			,theme: 'molv'
			,mark: {'{:$today}':''}
			,change: function(value, date, endDate){
				$('#create_date_range1').val(value);
				$('#layui-laydate2').remove();//关闭面板
			}
		});

		laydate.render({
			elem: '#stall_order_time'
			,range: '~'
			,theme: 'molv'
			,mark: {'{:$today}':''}
			,change: function(value, date, endDate){
				$('#stall_order_time').val(value);
				$('#layui-laydate3').remove();//关闭面板
			}
		});
		window.status=0;
		window.statCli = function(status) {
			var url='{:url("index")}?status='+status;
			window.status=status;
			$("#hisi-table-search").attr('action',url);
			$("#seacher").click();
			changetab=1;
		}

		var opTable=table.render({
			elem: '#dataTable'
			,url: '{:url("", ["status" => $status])}' //数据接口
			,page: true //开启分页
			//,skin: 'row'
			,even: true
			,limit: 30
			,limits: [30,50,100,150,200,500,1000,3000]
			,text: {
				none : '暂无相关数据'
			}
			,toolbar: '#toolbar'

			,defaultToolbar: ['exports', 'print']
			,cols: [[ //表头
				{type:'checkbox',field:'checkbox'}
				,{field: 'Ordernumred', title: '订单号', templet:'#OrdernumTpl_red',width:60}
				,{field: 'col1', title: '订单号', templet:'#OrdernumTpl',width:60}
				,{field: 'sku', title: 'SKU',templet:'#sku2Tpl',width:80}
				,{field: 'skuimg', title: '图片',templet:'#skuimgTpl',width:70}
				,{field: 'size_name', title: '尺码',width:50}
				,{field: 'order_count', title: '订单数',width:40}
				,{field: 'shicai_count', title: '裁床数',width:40}
				,{field: 'jiaohuo_count', title: '车间数',width:40}
				,{field: 'daohuo_count', title: '出货数',width:40}
				,{field: 'tail_goods_dff', title: '尾货差异（车间数-出货数）',edit:'text',width:80,style:'color:#3399FF;border-bottom:1px dashed #5FB878;'}
				,{field: 'stock_count', title: '现库存数',width:70}
				,{field: 'stock_outtype', title: '出入库存方式',width:50}
				,{field:'factory_name',title : '工厂',width:120}
				,{field: 'pack_status_stay', title: '状态',width:120}
				,{field: 'packageOrder_num', title: '大包编号/订单号',templet:'#packageOrder_num',width:120}
				,{field:'package_num',title : '大包编号',templet:'#packagenum',width:75}
				,{field: 'client_ordernum', templet:'#OrdernumTpl',title: '订单号',width:60}
				,{field:'total_num',title : '总件数',width:75,templet:"#total_num_new"}
				,{field: 'total_ordernum', title: '总单数',width:60}
				,{field: 'total_need_num', title: '需入库数量',templet:'#total_need_num',width:60}
				,{field: 'total_need_out_num', title: '需出库数量',templet:'#total_need_num_out',width:60}
				,{field: 'tail_goods_dff_end', title: '尾货差异数量',templet:'#tail_goods_dff_end',width:60}
				,{field: 'type', title: '操作类型',width:70}
				,{field: 'factory_name_two', title: '工厂',width:120}
				,{field: 'remark', title: '订单类型',width:120}
				,{field: 'tail_over_time', title: '尾完日期', templet: "#tail_over_time",width:160}
		        ,{field: 'create_package_time',templet: function(d){return layui.util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss')}, title: '大包生成日期',width:120}
		        ,{field: 'update_time',templet: function(d){return layui.util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm:ss')}, title: '日期',width:90}
				,{field: 'reason_content', title: '无需处理原因',width:100}
				,{field: 'd_status', title: '状态',width:70}

			]]
			,done: function(res, curr, count){
				var data=res.data;
				var status=res.status;
				layui.form.render();
				$(".searchSubmit").show();

				if(status==0){
					var need_field=[0,'checkbox','Ordernumred','sku','skuimg','size_name','order_count','shicai_count',
						'jiaohuo_count','daohuo_count','tail_goods_dff','stock_count','billing_caigou_count_feed','stock_outtype','factory_name','tail_over_time','pack_status_stay',
						];

					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					$('.make-bill').remove();
					$('.layui-form-item .layui-inline').show();
					$('.recheck').hide();
					$('.back').hide();
					$('.checkOutDetailedNew').hide();
					$('.cancelOrders').hide();

                    //搜索
					$('.package_num_search').hide();
					$('.order_type_search').hide();

				}else if(status==1){

					var need_field=['checkbox','package_num','client_ordernum','total_num','total_ordernum','total_need_num','factory_name_two','create_package_time','d_status']
					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					$('.check').remove();
					$('.layui-form-item .layui-inline').show();
					//$(".topsearch").show();
					$('.recheck').hide();
					$('.confirmon').hide();
					$('.checkOutDetailedNew').hide();
					$('.cancelOrders').hide();

					//搜索

					$('.order_type_search').hide();
					$('.sku_input_search').hide();
					$('.tail_stock_search').hide();
					$('.size_search_input').hide();

				}else if(status==2){

					var need_field=['checkbox','package_num','client_ordernum','total_num','total_ordernum','total_need_num','factory_name_two','create_time','d_status']

					$('table tr[data-index=0] td').each(function(i){

						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					$('.make-bill').remove();
					$('.check').remove();
					$('.back').remove();
					$('.confirmon').hide();

					$('.layui-form-item .layui-inline').show();
					//$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
					//$(".topsearch").hide();
					$('.checkOutDetailedNew').hide();

					//搜索

					$('.order_type_search').hide();
					$('.sku_input_search').hide();
					$('.tail_stock_search').hide();
					$('.size_search_input').hide();
				}else if(status==3){

					var need_field=['checkbox','client_ordernum','total_num','total_ordernum','total_need_out_num','factory_name_two','remark','tail_over_time','d_status']
					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});

					$('.make-bill').remove();
					$('.check').remove();
					$('.back').remove();
					$('.cancelOrders').hide();
					$('.checkOutDetailedNew').show();
					$('.confirmon').hide();

					$('.layui-form-item .layui-inline').show();
					// $('.layui-form-item .layui-inline').hide();
					//$(".searchSubmit").show();
					$('.recheck').show();
					$('.allsearch').show();
					$(".hisi-export").show();

					//搜索
					$('.sku_input_search').hide();
					$('.tail_stock_search').hide();
					$('.size_search_input').hide();
					$('.package_num_search').hide();

				}else if(status==4){
					var need_field=['checkbox','packageOrder_num','total_num','total_ordernum','tail_goods_dff_end','type','factory_name_two','update_time','reason_content','d_status']
					$('table tr[data-index=0] td').each(function(i){
						if(need_field.indexOf($(this).attr('data-field'))==-1){
							$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
							$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
						}
					});
					$('.confirmon').hide();

					$('.layui-table-tool').remove();


					//搜索
					$('.status_serarch').hide();
					$('.order_type_search').hide();
					$('.sku_input_search').hide();
					$('.tail_stock_search').hide();
					$('.size_search_input').hide();
				}

				if (res.statData != [] ) {
					var total=0,stat=res.statData;
					for(var i in stat) {
						total= total+Number(stat[i]);
					}

					$('.stat-num-1').text(stat[0]?stat[0]:0);
					$('.stat-num-2').text(stat[1]?stat[1]:0);
					$('.stat-num-3').text(stat[2]?stat[2]:0);
					$('.stat-num-4').text(stat[3]?stat[3]:0);
					$('.stat-num-5').text(stat[4]?stat[4]:0);
				}

				table.on('edit(demoEvent)', function(obj){

					var value = obj.value //得到修改后的值
							,d = obj.data //得到所在行所有键值
							,field = obj.field; //得到字段
					var id=d.id;

					// 编辑采购总金额
					if (field == 'tail_goods_dff') {
						$.ajax({
							type: "POST",
							url: "{:url('index')}?action=changeSkuDiff",
							data: "id="+d.id+"&tail_goods_dff="+value,
							dataType:"json",
							success: function(res){

								layer.msg('已修改', {icon: 1});
							}
						});
					}

				});

			}
		});

		form.on('select(stallIds)', function(data){
			var val=data.value,id=data.elem.id;
			var elem=($('#'+id));
			$.ajax({
				type: "POST",
				url: "{:url('stallFeedEdit')}",
				data: "id="+elem.attr("data-id")+"&stall_id="+elem.val(),
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						layer.msg(res.msg, {icon: 1});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
		});

		window.trRemove = function(n) {
			$('table tr td:nth-child('+n+')').remove();
			$('table tr th:nth-child('+n+')').remove();
		}

		//设置url参数值
		window.setUrlParam=function(tabs) {
			var para_name=[$(tabs).attr('name')];
			var para_value=[$(tabs).val()];

			//para_name, para_value
			var oUrl = $(".confirmSubmitCreateBill").eq(1).attr("data-href").toString();
			for(var i=0;i<para_name.length;i++)
			{
				var re=eval('/('+ para_name[i]+'=)([^&]*)/gi');
				oUrl= oUrl.replace(re,para_name[i]+'='+para_value[i]);
			}
			$(".confirmSubmitCreateBill").eq(1).attr("data-href",oUrl);
		}


		$(document).on('click','.confirmSubmitCreateBill',function(){
			layer.close(layerDefective);
		});

		window.openPackageWindow = function(select=0) {

			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var checkids='';
			var jsonlist='';
			var order_id_list='';
			var client_ordernum_list='';
			var that = $(document);
			var tableObj = that.attr('data-table') ? that.attr('data-table') : 'dataTable';
			var checkStatus = table.checkStatus(tableObj);
			var confirm_tip_mes="您确定要执行此操作吗？";
			// 尾货待处理： 新增入库单-101; 生成入库大单-102;发货-103,无需处理-104  新增入库单； 202 发货；
			// 打包待发货： 退出大货-201; 发货-202;打印清单-203,
			//入库：退货-301     出库： 打印清单-401；402调用库存

            //根据不同编码状态 获取对应的字段值
			for(var i=0;i<checkStatus.data.length;i++){
				checkdata=checkStatus.data;

				if(select==102 || select==103 || select==104){
					if(select==103 && checkdata[i]['tail_goods_dff'] >0){
						layer.msg('尾货差异为正数，不能出库!', {icon: 2,anim: 6});return;
					}

					checkids+=checkdata[i]['client_ordernum']+'|'+checkdata[i]['size_name']+'|'+checkdata[i]['tail_goods_dff']+',';
				}else if(select==401 ){
					checkids+=checkdata[i]['client_ordernum']+",";
				}else if(select==402){
					order_id_list += checkdata[i]['order_id']+",";
					client_ordernum_list += checkdata[i]['client_ordernum']+",";
					jsonlist += checkdata[i]['otherStockList_json'];
				}
				else if(select==202 || select==301 || select==201 || select==203 ){
					checkids+=checkdata[i]['package_num']+",";
				}
			}
             //打印清单
			if(select==203 || select==401){
				openCheckoutWindow(checkids,window.status);
				return;
			}
			//调用库存
			if(select==402){
				openCallInventoryWindow(jsonlist,order_id_list,client_ordernum_list,window.status);
			}

            //生成大包 弹出
			if(select==102){
				var title='生成大包';
				layerStockOutIn = layer.open({
					type: 2
					,area: ['800px','600px']
					,offset: 'auto'
					,shade:[0.3, '#393D49']
					,anim: 5
					,skin:'layui-layer-molv'
					,shadeClose:true
					,title:title
					,content: "{:url('creatPackage')}?ids_str="+checkids
				});
			}
			//无需处理
			if(select==104){
				var title='请选择原因';
				layerStockOutIn = layer.open({
					type: 2
					,area: ['500px','400px']
					,offset: 'auto'
					,shade:[0.3, '#393D49']
					,anim: 5
					,skin:'layui-layer-molv'
					,shadeClose:true
					,title:title
					,content: "{:url('notNeedHandle')}?ids_str="+checkids
				});
			}

			if(select==202 || select==103 || select==301 || select==201 || select==401 ){


				switch (select) {
                    case 103:
						var urlPosts="{:url('index')}";
						var actionFun="checkout";
						break;
					case 202:
						var urlPosts="{:url('index')}";
						var actionFun="delivery";
						break;
					case 301:
						var urlPosts="{:url('index')}";
						var actionFun="cancelOrders";
						break;
					case 201:
						var urlPosts="{:url('index')}";
						var actionFun="cancelBigOrders";
						break;
				}

				layer.confirm(confirm_tip_mes, {icon: 3,title:false, closeBtn:0, btn: ['确定','取消']}
				, function(){
					$.post(urlPosts, {action:actionFun,ids_str:checkids}, function (res) {
						if (res.code == 1) {
							layer.msg(res.msg, {time: 1000, icon: 1}, function () {
								//statCli(1);
								reloadTable();
							});
						} else {
							layer.msg(res.msg, {time: 1800, icon: 2});
							//移除按钮状态
							$(':button').removeClass(DISABLED);
							$(':button').removeAttr('disabled');
						}
					}, 'json');
				}, function(){
					layer.closeAll();
				});
			}

		}

		//详细
		window.openCheckoutWindow = function(package_num='',status=0,field_type='package_num',status_two=0) {

			var title,idnum;
			var widthDetail='900px';
			var heightDetail='600px';

			if(status==3){
				 title='出库清单';
				var idnum="field_type="+field_type+"&client_ordernum="+package_num;
			}else{
				if(status==1){
					title='大包尾货清单';
				}else if(status==2){
					title='入库清单';
					widthDetail='1000px';
					heightDetail='700px';
				}
				if(status==-100){
					title='完成清单';
					idnum="field_type="+field_type+"&package_num="+package_num+"&status_two="+status_two;
				}else{
					idnum="field_type="+field_type+"&package_num="+package_num;
				}
			}

			layerStockOutIn = layer.open({
				type: 2
				,area: [widthDetail,heightDetail]
				,offset: 'auto'
				,shade:[0.1, '#393D49']
				,anim: 5
				,skin:'demo-class'
				,shadeClose:true
				,title:title
				,content: "{:url('index')}?action=detailList&"+idnum+"&status="+status
			});
		}
		//新增入库单
		window.addInvoice =function (){
			var title='新增入库单';
			layerStockOutIn = layer.open({
				type: 2
				,area: ['500px','400px']
				,offset: 'auto'
				,shade:[0.3, '#393D49']
				,anim: 5
				,skin:'layui-layer-molv'
				,shadeClose:true
				,title:title
				,content: "{:url('addInvoice')}"
			});
		}
		//调用库存
		var sku_stock='';
	    window.openCallInventoryWindow = function(dress_line_code_list='',order_id_list='',client_ordernum_list='',status=0) {
			sku_stock=dress_line_code_list;
			console.log(sku_stock);
			var d = [];
			d['url'] = "{:url('stockCheckOut')}?order_id="+order_id_list;
			d['order_id'] = order_id_list;
			d['client_ordernum'] = client_ordernum_list;
			d['sku_stock'] = dress_line_code_list;
			$(".size_name_span").html("__");
			$(".size_name_input").val('');
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".out_code_input").focus();
			var content = laytpl($('#StockCheckOut').html()).render(d);
			layerStockOut = layer.open({
				type: 1
				,area: ['660px','320px']
				,offset: '100px'
				//,shade:[0.8, '#393D49']
				,anim: 5
				,skin:'layui-layer-molv'
				,title:'库存调用-你选择占用库存的订单号：'+client_ordernum_list
				,content: content
				,success:function(layerdom,index){
					$(".out_code_input").eq(1).focus();
				}
			});
		};

		$(document).on('input propertychange',".out_code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var code_str=',';
			console.log(sku_stock);
			code_str=sku_stock;
			if(dress_line_code.length==17){
				dress_line_code=dress_line_code+"\n";
			}
			var codeNumbers=dress_line_code.split("\n");
			var last_input=codeNumbers[codeNumbers.length-1];
			var r, re;
			var re = eval('/'+last_input+'/ig');
			r = dress_line_code.match(re);   //匹配字符
			$(".scan_code_ret").html('');

			for(var i=0;i<codeNumbers.length;i++){
				if(code_str.indexOf(codeNumbers[i])!=-1){
				}else{
					$(".scan_code_ret").eq(1).html("未找到"+codeNumbers[i]+"的库存信息或该条码不属于当前sku");
				}
			}
			if(codeNumbers[codeNumbers.length-1].length>=17){
				//$(".code_input").eq(1).val(dress_line_code+'\n');
			}
			$(".outcheckinNum").val(codeNumbers.length);
			$(".checkInNumSpan").html(codeNumbers.length);
		});

		form.on('submit(stock-out-out)', function (data) {
			var url = data.field.url;
			$.ajax({
				type: "POST",
				url: url,
				data: data.field,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						$('#stockOutInTpl form')[0].reset();
						$(".total_stock").html(res.data.available_count);
						$(".scan_code").hide();
						$(".checkin_ret").show();
						$(".act_ret_str").html(res.data.act_ret_str);
						layer.msg(res.msg, {icon: 1,end:function(){
								opTable.reload();
								layer.close(layerStockOut);
							}});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
			return false;
		});
		$(document).on('mouseover', '.help-diy-css', function(data){
			var that = this;
			tips =layer.tips('<br/><span >1.MES系统所有子单创建发货单后，在“尾部进度” 点击 "尾部完成"或"同步发货单" 或"无发货单" 任一按钮，订单3分钟内流转进入；</span><br/>'+
			' <span> 2.尾货差异正数为入库，负数则为出库；尾货差异支持修改；</span><br/>' +
			' <span>3.尾货差异为0时，订单任务不出现；  </span><br/>' +
			'  <span>4.不出现的订单支持手工新增。  </span><br/><br/><br/>',
			this,{tips:[2,'#3595CC'],time:0,area: 'auto',maxWidth:720});
		}).on('mouseleave', '.help-diy-css', function(){
			layer.close(tips);
		    });
		// 刷新当前页
		window.reloadTable = function () {

			var that = $("#hisi-table-search"),
					arr = that.serializeArray(),
					where = new Array(),
					dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',

					currPage = $(".layui-laypage-em").next().html(),
					options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
			for(var i in arr) {
				where[arr[i].name] = arr[i].value;
			}
			options.url = that.attr('action');
			options.where = where;

			opTable.reload(options);
			return false;
		}

	});
</script>